import { Controller, Post, Body, UseGuards, Req, Get } from '@nestjs/common';
import { SendMessageDto } from './dto/send-message.dto';
import { MessagesService } from './messages.service';
import { AuthGuard } from '@nestjs/passport';
import { JwtRequest } from 'src/auth/interfaces/jwt-request.interface';

@Controller('message')
@UseGuards(AuthGuard())
export class MessagesController {
  constructor(private readonly messagesService: MessagesService) {}

  @Post()
  sendMessage(@Body() sendMessageDto: SendMessageDto, @Req() req: JwtRequest) {
    return this.messagesService.sendMessage(req.user.account, sendMessageDto);
  }

  @Get()
  async getMessages() {
    return await this.messagesService.findMessage();
  }
}
